package com.tgy.leetcode;

public class _190_颠倒二进制位 {

    // you need treat n as an unsigned value
    public static int reverseBits(int n) {

        int result = 0;

        for (int i = 0; i < 32 && n != 0; i++) {

            result |= ((n & 1) << (31 - i));
            n = (n >>> 1);
        }
        return result;
    }

    public static void main(String[] args) {

        System.out.println(reverseBits(-3));

    }
}
